<template>
  <div id="concernModal">
    <div class="infor-content" v-if="ctnIndex == 0">
      <div class="infor-right" v-loading="loading">
        <div class="account">
          全部关注
          <span class="favor-num">{{ count }}</span>
        </div>
        <div class="fansCtn" v-if="res.articleShow">
          <div class="article" v-for="(item, index) in artList" :key="index">
            <div class="fansHeader">
              <div class="article-header" @click="goUp(item.userId)">
                <img :src="item.headImage" alt />
              </div>
              <div class="fansIcon" v-if="item.identity == 1">
                <img src="../assets/imgs/xhv.png" alt="" />
              </div>
              <div class="fansIcon" v-if="item.identity == 2">
                <img src="../assets/imgs/xlv.png" alt="" />
              </div>
              <div class="fansIcon" v-if="item.identity == 3">
                <img src="../assets/imgs/green.png" alt="" />
              </div>
            </div>
            <div class="article-name">
              <span>{{ item.nickName }}</span>
            </div>
            <div class="fansIntro" :title="item.introduce">
              {{ item.introduce }}
            </div>
          </div>
        </div>
        <div class="infor-right noList" v-else>当前还没有内容哦~</div>
      </div>
    </div>
    <div class="infor-content" v-else-if="ctnIndex == 1">
      <div class="infor-right" v-loading="loading">
        <div class="account">
          全部粉丝
          <span class="favor-num">{{ count }}</span>
        </div>
        <div class="fansCtn" v-if="res.articleShow">
          <div class="article" v-for="(item, index) in artList" :key="index">
            <div class="fansHeader">
              <div class="article-header" @click="goUp(item.userId)">
                <img :src="item.headImage" alt />
              </div>
              <div class="fansIcon" v-if="item.identity == 1">
                <img src="../assets/imgs/xhv.png" alt="" />
              </div>
              <div class="fansIcon" v-if="item.identity == 2">
                <img src="../assets/imgs/xlv.png" alt="" />
              </div>
              <div class="fansIcon" v-if="item.identity == 3">
                <img src="../assets/imgs/green.png" alt="" />
              </div>
            </div>
            <div class="article-name">
              <span>{{ item.nickName }}</span>
            </div>
            <div class="fansIntro" :title="item.introduce">
              {{ item.introduce }}
            </div>
          </div>
        </div>
        <div class="infor-right noList" v-else>当前还没有内容哦~</div>
      </div>
    </div>
    <div class="paging" v-if="res.articleShow">
      <el-pagination
        layout="prev, pager, next"
        :total="count"
        :page-size="20"
        :background="true"
        @current-change="changePage"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    modalIndex: {
      type: Number,
    },
  },
  data() {
    return {
      ctnIndex: 0,
      list: [],
      user: "",
      artList: [],
      loading: true,
      id: 0,
      res: "",
      count: 0,
    };
  },
  watch: {
    modalIndex: {
      handler(newVal, oldVal) {
        console.log(newVal);
        console.log(oldVal);
        this.ctnIndex = newVal;
        this.ctnIndex == 0
          ? this.init(`/follow/frontend/followlist`, "list", 1)
          : this.init(`/follow/frontend/fanslist`, "list", 1);
      },
      immediate: true,
    },
  },
  methods: {
    init(url, listName, page) {
      this.loading = true;
      this.$fetch(`/laiwen/${url}?page=${page}&limit=20`, {}).then((res) => {
        this.loading = false;
        this.totalPage = res.totalPages * 1;
        this.count = res.count * 1;
        console.log(this.totalPage);
        this.res = res;
        this.$set(res, "articleShow", true);
        this.artList = res[listName];
        //list为空的样式处理
        if (this.artList.length == 0) {
          this.$set(res, "articleShow", false);
        }
        console.log(this.artList);
      });
    },
    //接受子组件index
    getIndex(e) {
      this.ctnIndex = e;
      this.isSpecial = true;
      if (e == 0) {
        this.init(`/follow/frontend/followlist`, "list", 1);
      }
      if (e == 1) {
        this.init(`/follow/frontend/fanslist`, "list", 1);
      }
    },

    //分页方法
    changePage(size) {
      if (this.ctnIndex == 0) {
        this.init(`/follow/frontend/followlist`, "list", size);
      } else if (this.ctnIndex == 1) {
        this.init(`/follow/frontend/fanslist`, "list", size);
      }
    },
    jumpPage(path, id) {
      this.navigate(path, id);
    },
    //Up主页面
    goUp(id) {
      this.$router.push({
        path: "/home",
        query: { id: id },
      });
    },
  },
  mounted() {
    this.getRem(1920, 100);
  },
};
</script>

<style scoped src="../assets/css/PersonModal.css"></style>
